// running
// gcc -std=c99 -o cproctest cproctest.c

// single processor core 2duo desktop no stdlib - 2500 execv/sec

#include <unistd.h>
#include <stdlib.h>

void main(int argc, char** argv){
  char* countStr = argv[1];
  //int count = (countStr[0]-'0')*1000 + (countStr[1]-'0')*100 + (countStr[2]-'0')*10 + countStr[3]-'0';
  int count = atoi(countStr);
//  write(1,countStr,3);
  if( count>0 ){
//    sleep(2);
//    if( fork()==0 ){
        char* pname = "cproctest";
        char countNew[5];
	countNew[0] = '0'+(count-1)/1000;
	countNew[1] = '0'+(count-1)/100%10;
	countNew[2] = '0'+(count-1)/10%10;
	countNew[3] = '0'+(count-1)%10;
	countNew[4] = 0;
        char* const newArgs[] = {pname, countNew, "mm",0};
	execv("./cproctest",newArgs);
        write(1,"aa\n",2);
//    }
  }
}


